import { h } from '@logicflow/core';
import { BaseOutModel, BaseOutView } from '../base/BaseOutNode';

const getDynamicOutModelDefinition = (type: string, text = 'DynamicOut', icon = '') => {
  class DynamicOutModel extends BaseOutModel {
    initNodeData(data: any): void {
      super.initNodeData(data);
      this.text.value = text;
    }
  }

  class DynamicOutView extends BaseOutView {
    getIcon() {
      if (!icon) {
        return super.getIcon();
      }
      const { x, y } = this.props.model;
      const width = 30;
      const height = 40;
      return h('image', {
        width,
        height,
        x: x - width / 2,
        y: y - height / 2 - 3,
        href: icon,
      });
    }
  }
  return {
    type: type,
    view: DynamicOutView,
    model: DynamicOutModel,
  };
};

export default getDynamicOutModelDefinition;
